# Copyright 2022 Dakewe Biotech Corporation.
# Licensed under the Apache License, Version 2.0 (the "License");
# The following code is to convert the mrc file to jpg.
# ==============================================================================
# Re-implementation of "Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network"
# Author: MiQroEra
# ==============================================================================

import mrcfile
import numpy as np
import cv2
import os

with mrcfile.open('GTSIM_level_01.mrc', permissive=True) as mrc:
    data = np.array(mrc.data)

data = (data - data.min()) / (data.max() - data.min()) * 255
data = data.astype(np.uint8)

img = cv2.cvtColor(data, cv2.COLOR_GRAY2BGR)

filename = os.path.splitext(os.path.basename('GTSIM_level_01.mrc'))[0] + '.jpg'
cv2.imwrite(filename, img)

print('Saved image as', filename)